<?php defined('BASEPATH') OR exit('No direct script access allowed');

// Code here is run before ALL controllers
class MY_Controller extends CI_Controller {

	// Deprecated: No longer used globally
	protected $data;
	public $module;
	public $controller;
	public $method;

	public function MY_Controller()
	{
		parent::__construct();

		$this->module = $this->router->fetch_module();
		$this->controller = $this->router->fetch_class();
		$this->method = $this->router->fetch_method();
		
		$this->user = $this->ion_auth->get_user();
		// Loaded after $this->user is set so that data can be used everywhere
		$this->load->model(array(
			'permissions/permission_m',
			'modules/module_m'
		));

		// List available module permissions for this user
		$this->permissions = $this->user ? $this->permission_m->get_group($this->user->group_id) : array();

		// Get meta data for the module
//		$this->template->module_details = $this->module_details = $this->module_m->get($this->module);
//
//		empty($this->module_details['enabled']) AND show_404();
//
//		if (!$this->module_details['skip_xss'])
//		{
//			$_POST = $this->security->xss_clean($_POST);
//		}
                $site_lang = Settings::get('site_lang');                                
                
                define('CURRENT_LANGUAGE', $site_lang);
                
                
		$langs = $this->config->item('supported_languages');                

		$gicms['lang'] = $langs[CURRENT_LANGUAGE];
		$gicms['lang']['code'] = CURRENT_LANGUAGE;                
     
                //$this->data['module_title'] = FALSE;
		$this->load->vars($gicms);
                
                //print_r($this->load->_ci_cached_vars['lang']); die;
                
//		$this->benchmark->mark('my_controller_end');
                define('_SYS_IMG_DIR_', site_url('assets/img'));
                define('_SYS_CSS_DIR_', site_url('assets/css'));
                define('_SYS_UPLOAD_DIR_', site_url('assets/uploads'));
                define('_THEME_FRONTEND_', site_url('assets/themes_frontend'));                
                define('_THEME_ADMIN_', site_url('assets/themes_admin'));
                define('_THEME_UP_', site_url('assets/themes_uyp'));
                define('_THEME_UB', site_url('assets/themes_ub'));   

        }

	protected function is_ajax()
	{
		return $this->input->server('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
	}
}

/**
 * Returns the CI object.
 *
 * Example: ci()->db->get('table');
 *
 * @staticvar	object	$ci
 * @return		object
 */
function ci()
{
	return get_instance();
}
